//
//  NicknameViewController.m
//  FeiYan
//
//  Created by 伟大大 on 2017/3/7.
//  Copyright © 2017年 伟帅陈. All rights reserved.
//

#import "NicknameViewController.h"
#import "LoginViewController.h"
@interface NicknameViewController ()

@end

@implementation NicknameViewController

#pragma mark -
#pragma lifeCircle
#pragma mark -
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    [theApp hiddenBottomView];
    
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    //    [theApp showBottomView];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    if ([self.XGtype isEqualToString:@"1"]) {
//
//
//    }else if ([self.XGtype isEqualToString:@"2"]) {
//        self.title = @"修改性别";
//
//    }else {
//        self.title = @"修改手机号";
//
//    }
    self.title = @"修改昵称";
    
    self.view.backgroundColor = BACKCOLOR;
    [self.navigationController.navigationBar setTitleTextAttributes:
     
     @{NSFontAttributeName:[UIFont systemFontOfSize:17],
       
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.barTintColor = BLUECOLOR;
    
    
    [self initNavBtns];
    [self initViews];
    // Do any additional setup after loading the view.
}
#pragma mark -
#pragma mark for views
#pragma mark -

- (void)initNavBtns {
    
    self.navigationItem.leftBarButtonItem = [AppUtility getNavBtnItemLefBacktWith:@selector(leftNavBtnClicked) andTarget:self];
}
- (void)initViews
{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0*theApp.autoSizeScaleY, [AppUtility screenWidth], 30*theApp.autoSizeScaleY)];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    
//    UILabel *textLabel = [[UILabel alloc]initWithFrame:CGRectMake(13*theApp.autoSizeScaleX, 9*theApp.autoSizeScaleY, 60*theApp.autoSizeScaleX, 30*theApp.autoSizeScaleY)];
//    textLabel.font = [UIFont systemFontOfSize:13];
//
//    if ([self.XGtype isEqualToString:@"1"]) {
//        textLabel.text = @"昵称";
//
//
//    }else if ([self.XGtype isEqualToString:@"2"]) {
//        textLabel.text = @"性别";
//
//
//    }else {
//        textLabel.text = @"手机号";
//
//
//    }
//    textLabel.tag = 333;
//    textLabel.textColor = RGBCOLOR(68, 68, 68);
//    [bgView addSubview:textLabel];
    
    //    UIImageView *spliteView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 44, 320, 1)];
    //    spliteView.backgroundColor = RGBCOLOR(233, 240, 241);
    //    [self.view addSubview:spliteView];
    
    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(13*theApp.autoSizeScaleX, 0, 230*theApp.autoSizeScaleX, 30*theApp.autoSizeScaleY)];
    textField.font = [UIFont systemFontOfSize:13];
    textField.tag = 33;
    textField.textAlignment = NSTextAlignmentLeft;
    textField.backgroundColor = [UIColor clearColor];
    textField.text = self.nickname;
    textField.placeholder = @"请输入昵称";
    textField.returnKeyType = UIReturnKeyDone;
    textField.delegate = self;
    textField.textColor = RGBCOLOR(120, 120, 120);
    [bgView addSubview:textField];
    
    UIButton *login =[UIButton buttonWithType:UIButtonTypeCustom];
    login.frame =CGRectMake(8*theApp.autoSizeScaleX, bgView.frame.origin.y+bgView.frame.size.height+40*theApp.autoSizeScaleY, [AppUtility screenWidth]-16*theApp.autoSizeScaleX, 35*theApp.autoSizeScaleY);
    [login setBackgroundColor:BLUECOLOR];
    [login setTitle:@"确定" forState:UIControlStateNormal];
    login.layer.cornerRadius = 4.5;
    //        login.layer.borderWidth = 1.0;
    [login.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [login addTarget:self action:@selector(TijiaoClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:login];
    
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouched)];
    //    tap.delegate = self;
    [self.view addGestureRecognizer:tap1];

}
#pragma mark -
#pragma mark for events
#pragma mark -
- (void)leftNavBtnClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)tapTouched{
    UITextField *textField = (UITextField *)[self.view viewWithTag:33];

    if ([textField isFirstResponder]) {
        [textField resignFirstResponder];
    }
   
    
    
}
- (void)TijiaoClicked
{
    UITextField *textField = (UITextField *)[self.view viewWithTag:33];
    
    NSString *postStr = @"";
//    NSString *sex = @"";

    postStr = [NSString stringWithFormat:@"userid=%@&uname=%@",@"",textField.text];

//    if ([self.XGtype isEqualToString:@"1"]) {
//
//        postStr = [NSString stringWithFormat:@"&uname=%@",textField.text];
//
//    }else if ([self.XGtype isEqualToString:@"2"]) {
//        if ([textField.text isEqualToString:@"男"]) {
//            sex = @"1";
//        }else if ([textField.text isEqualToString:@"女"]) {
//            sex = @"2";
//        }
//        postStr = [NSString stringWithFormat:@"&sex=%@",sex];
//
//    }
    
    NSDictionary *resultDict =[NetUtility getDataWithURLStr:KURLXGUserInfo andPostStr:postStr andView:self.navigationController.view];
    
    UEXNSLog(@"kURL==%@%@ resultDict=%@",KURLXGUserInfo,postStr,resultDict);
    
    if (resultDict) {
        int stauts = [[resultDict objectForKey:@"s"] intValue];
        
        if (stauts==1) {
            
//            NSMutableDictionary *dic =[NSMutableDictionary dictionaryWithDictionary: [AccountController getAccountInfo]];
//
//            [dic setObject:textField.text forKey:@"nickname"];
//            [AccountController setAccountInfo:dic];
            
            [self.navigationController popViewControllerAnimated:YES];
        }else if (stauts == 303) {
            
            LoginViewController *vc = [[LoginViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            return;
        }
        
        [self.navigationController.view makeToast:[resultDict objectForKey:@"i"]];
    }
    
}
#pragma mark -
#pragma mark for delegates
#pragma mark -

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    
//    if ([self.XGtype isEqualToString:@"2"]) {
//
//        if (![textField.text isEqualToString: @"男"]&&![textField.text isEqualToString: @"女"]) {
//            [self.view makeToast:@"请输入正确的性别"];
//
//        }else {
//
//        }
//    }
    
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
